package cn.edu.wynu.loop;

public class ForDemo02 {
    public static void main(String[] args) {
        // 打印100以内的所有偶数
        for (int i = 1; i <= 100; i++) {
            // if分支判断是否为偶数
            if (i % 2 == 0) {
                System.out.println(i);
            }
        }
        System.out.println("------------------------");
        for (int i = 2; i <= 100; i += 2) {
            System.out.println(i);
        }
        System.out.println("------------------------");
        // 生成1~100所有数据
        for (int i = 1;i<=100;i++){
            System.out.println(i);
        }
        System.out.println("------------------------");
        // 求1~100的和
        int sum = 0;
        for (int i = 1;i<=100;i++){
            sum += i;
        }
        System.out.println("和为："+sum);
    }
}
